home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / pyshared / gst-0.10 / gst / __init__.py
Encoding:
Python Source  |  2009-02-21  |  6.6 KB  |  230 lines

  1. # -*- Mode: Python -*-
  2. # vi:si:et:sw=4:sts=4:ts=4
  3. #
  4. # gst-python
  5. # Copyright (C) 2002 David I. Lehn
  6. #
  7. # This library is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU Library General Public
  9. # License as published by the Free Software Foundation; either
  10. # version 2 of the License, or (at your option) any later version.
  11. #
  12. # This library is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15. # Library General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Library General Public
  18. # License along with this library; if not, write to the
  19. # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. # Boston, MA 02111-1307, USA.
  21. # Author: David I. Lehn <dlehn@users.sourceforge.net>
  22.  
  23. __gstltihooks_used__ = False
  24. try:
  25.     import gstltihooks
  26.     __gstltihooks_used__ = True
  27. except:
  28.     pass
  29.  
  30. import sys
  31.  
  32. # we always require 2.0 of pygtk; so if pygtk is not imported anywhere
  33. # yet, we import pygtk here and .require
  34. if 'gobject' not in sys.modules:
  35.     import pygtk
  36.     pygtk.require('2.0')
  37.  
  38. class Value:
  39.     def __init__(self, type):
  40.         assert type in ('fourcc', 'intrange', 'doublerange', 'fractionrange', 'fraction')
  41.         self.type = type
  42.  
  43. class Fourcc(Value):
  44.     def __init__(self, string):
  45.         Value.__init__(self, 'fourcc')
  46.         self.fourcc = string
  47.     
  48.     def __repr__(self):
  49.         return '<gst.Fourcc %s>' % self.fourcc
  50.     
  51.     def __eq__(self, other):
  52.         if isinstance(other, Fourcc):
  53.             return self.fourcc == other.fourcc
  54.  
  55.         return False
  56.  
  57.     def __ne__(self, other):
  58.         return not self.__eq__(other)
  59.  
  60. class IntRange(Value):
  61.     def __init__(self, low, high):
  62.         Value.__init__(self, 'intrange')
  63.         self.low = low
  64.         self.high = high
  65.     def __repr__(self):
  66.         return '<gst.IntRange [%d, %d]>' % (self.low, self.high)
  67.  
  68. class DoubleRange(Value):
  69.     def __init__(self, low, high):
  70.         Value.__init__(self, 'doublerange')
  71.         self.low = low
  72.         self.high = high
  73.     def __repr__(self):
  74.         return '<gst.DoubleRange [%f, %f]>' % (self.low, self.high)
  75.  
  76. class FractionRange(Value):
  77.     def __init__(self, low, high):
  78.         Value.__init__(self, 'fractionrange')
  79.         self.low = low
  80.         self.high = high
  81.     def __repr__(self):
  82.         return '<gst.FractionRange [%d/%d, %d/%d]>' % (self.low.num,
  83.                                                        self.low.denom,
  84.                                                        self.high.num,
  85.                                                        self.high.denom)
  86.  
  87. class Fraction(Value):
  88.     def __init__(self, num, denom=1):
  89.         def __gcd(a,b):
  90.             while b != 0:
  91.                 tmp = a
  92.                 a = b
  93.                 b = tmp % b
  94.             return abs(a)
  95.  
  96.         def __simplify():
  97.             num = self.num
  98.             denom = self.denom
  99.     
  100.             if num < 0:
  101.                 num = -num
  102.                 denom = -denom
  103.     
  104.             # Compute greatest common divisor
  105.             gcd = __gcd(num,denom)
  106.             if gcd != 0:
  107.               num /= gcd
  108.               denom /= gcd
  109.     
  110.             self.num = num
  111.             self.denom = denom
  112.  
  113.         Value.__init__(self, 'fraction')
  114.     
  115.         self.num = num
  116.         self.denom = denom
  117.  
  118.         __simplify()
  119.  
  120.     def __repr__(self):
  121.         return '<gst.Fraction %d/%d>' % (self.num, self.denom)
  122.  
  123.     def __eq__(self, other):
  124.         if isinstance(other, Fraction):
  125.             return self.num * other.denom == other.num * self.denom
  126.         return False
  127.  
  128.     def __ne__(self, other):
  129.         return not self.__eq__(other)
  130.  
  131.     def __mul__(self, other):
  132.         if isinstance(other, Fraction):
  133.             return Fraction(self.num * other.num,
  134.                             self.denom * other.denom)
  135.         elif isinstance(other, int):
  136.             return Fraction(self.num * other, self.denom)
  137.         raise TypeError
  138.  
  139.     __rmul__ = __mul__
  140.  
  141.     def __div__(self, other):
  142.         if isinstance(other, Fraction):
  143.             return Fraction(self.num * other.denom,
  144.                             self.denom * other.num)
  145.         elif isinstance(other, int):
  146.             return Fraction(self.num, self.denom * other)
  147.         return TypeError
  148.  
  149.     def __rdiv__(self, other):
  150.         if isinstance(other, int):
  151.             return Fraction(self.denom * other, self.num)
  152.         return TypeError
  153.  
  154.     def __float__(self):
  155.         return float(self.num) / float(self.denom)
  156.  
  157. import sys
  158. try:
  159.     dlsave = sys.getdlopenflags()
  160.     from DLFCN import RTLD_GLOBAL, RTLD_LAZY
  161. except AttributeError:
  162.     # windows doesn't have sys.getdlopenflags()
  163.     RTLD_GLOBAL = -1
  164.     RTLD_LAZY = -1
  165. except ImportError:
  166.     RTLD_GLOBAL = -1
  167.     RTLD_LAZY = -1
  168.     import os
  169.     osname = os.uname()[0]
  170.     if osname == 'Linux' or osname == 'SunOS' or osname == 'FreeBSD':
  171.         machinename = os.uname()[4]
  172.         if machinename == 'mips' or machinename == 'mips64':
  173.             RTLD_GLOBAL = 0x4
  174.             RTLD_LAZY = 0x1
  175.         else:
  176.             RTLD_GLOBAL = 0x100
  177.             RTLD_LAZY = 0x1
  178.     elif osname == 'Darwin':
  179.         RTLD_GLOBAL = 0x8
  180.         RTLD_LAZY = 0x1
  181.     del os
  182. except:
  183.     RTLD_GLOBAL = -1
  184.     RTLD_LAZY = -1
  185.  
  186. if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
  187.     sys.setdlopenflags(RTLD_LAZY | RTLD_GLOBAL)
  188.  
  189. try:
  190.     import libxml2
  191. except:
  192.     pass
  193. from _gst import *
  194. import interfaces
  195.  
  196. if RTLD_GLOBAL != -1 and RTLD_LAZY != -1:
  197.     sys.setdlopenflags(dlsave)
  198. del sys
  199.  
  200. version = get_gst_version
  201.  
  202. # Fixes for API cleanups that would cause an API breakage.
  203. # See #446674
  204.  
  205. import warnings
  206. if locals().has_key("parse_bin_from_description"):
  207.     def gst_parse_bin_from_description(*args, **kwargs):
  208.         warnings.warn("gst_parse_bin_from_description() is deprecated, please use parse_bin_from_description instead",
  209.                       DeprecationWarning)
  210.         return parse_bin_from_description(*args, **kwargs)
  211.  
  212. if locals().has_key("message_new_buffering"):
  213.     def gst_message_new_buffering(*args, **kwargs):
  214.         warnings.warn("gst_message_new_buffering() is deprecated, please use message_new_buffering() instead",
  215.                       DeprecationWarning)
  216.         return message_new_buffering(*args, **kwargs)
  217.  
  218. # this restores previously installed importhooks, so we don't interfere
  219. # with other people's module importers
  220. # it also clears out the module completely as if it were never loaded,
  221. # so that if anyone else imports gstltihooks the hooks get installed
  222. if __gstltihooks_used__:
  223.     gstltihooks.uninstall()
  224.     __gstltihooks_used__ = False
  225.     del gstltihooks
  226.     import sys
  227.     del sys.modules['gstltihooks']
  228.  
  229.